#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <vector>
#include <functional>
#include <string>

using func_t = std::function<void()>;
std::vector<func_t> funcs;

void Fflush()
{
    std::cout << "flush" << std::endl;
}

void Download()
{
    std::cout << "download" << std::endl;
}

void Upload()
{
    std::cout << "upload" << std::endl;
}

void handler(int sig)
{
    std::cout<<"##############"<<std::endl;
    for (auto &f : funcs)
    {
        f();
    }
    std::cout<<"##############"<<std::endl;


    int n = alarm(1);
    std::cout << "剩余时间: " << n << std::endl;
}

int main()
{

    funcs.push_back(Fflush);
    funcs.push_back(Download);
    funcs.push_back(Upload);

    signal(SIGALRM, handler);
    alarm(1);

    while (1)
    {
        pause();
    }

    return 0;
}